package cn.ylg.com.addfragment;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import cn.ylg.com.addfragment.fragment.NiceFragment;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void addView(View view){
        //获取fragment事物
        FragmentTransaction ftr = getSupportFragmentManager().beginTransaction();
        //fragment 切换添加动画；
        ftr.setCustomAnimations(R.anim.slide_in,R.anim.slide_out,R.anim.slide_in,R.anim.slide_out);
        //使用事物添加fragment
        ftr.add(R.id.main_container,NiceFragment.newInstance(1));//多个fragment进行切换
      //  ftr.replace(R.id.main_container,new NiceFragment());//把当前容器换成fragment，前提只是为了替换
        ftr.addToBackStack(null);//把当前fragment添加到回退栈中
        //提交；
        ftr.commit();
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }
}
